package com.xingzhi.common.util;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;

import java.util.Map;

/**
 * Created by daniel.luo on 2018/6/20.
 */
public class SmsUtil {
    public static final String APIKEY = "b7acfb3c290994bf8a62bac9c523fca6";

    public static int singleSend(String text, String mobile) throws Exception {
        YunpianClient client = new YunpianClient(APIKEY);
        Map<String, String> params = client.newParam(2);
        params.put("text", text);
        params.put("mobile", mobile);
        client.init();
        Result<SmsSingleSend> ret = client.sms().single_send(params);
        client.close();
        return ret.getCode();
    }

    /**
     * 发送短信验证码
     * @param code
     * @param mobile
     * @return
     * @throws Exception
     */
    public static int sendVCode(String name, String alive, String code, String mobile) throws Exception {
        String text = "【行知在线】亲爱的" + name + "，您的验证码是" + code + "。有效期为" + alive + "分钟，请尽快验证";
        return singleSend(text, mobile);
    }
}
